package com.seamtop.cuber.common.metadata;

import com.seamtop.cuber.common.exception.CuberFileParseException;

/**
 * Created by zongjunfeng on 2015/8/11.
 */
public class ValueTypeContants {

    public static int VALUE_TYPE_STRING = 1;

    public static int VALUE_TYPE_INT = 2;

    public static int VALUE_TYPE_LONG = 3;

    public static int VALUE_TYPE_FLOAT = 4;

    public static int VALUE_TYPE_DOUBLE = 5;

    public static int VALUE_TYPE_DATE = 6;

    public static int VALUE_TYPE_DATE_TIMESTAMP = 7;


    public static int getKeyType(String keyType){
        if("string".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_STRING;
        }else if("int".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_INT;
        }else if("float".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_FLOAT;
        }else if("double".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_DOUBLE;
        }else if("long".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_LONG;
        }else if("date".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_DATE;
        }else if("timestamp".equals(keyType)){
            return ValueTypeContants.VALUE_TYPE_DATE_TIMESTAMP;
        }else {
            return ValueTypeContants.VALUE_TYPE_STRING;
        }
    }


    public static String getKeyTypeDesc(int keyType){
        String result = "";
        switch (keyType){
            case 1:
                result = "string";
                break;
            case 2:
                result = "int";
                break;
            case 3:
                result = "long";
                break;
            case 4:
                result = "float";
                break;
            case 5:
                result = "double";
                break;
            case 6:
                result = "date";
                break;
            case 7:
                result = "timestamp";
                break;
            default:
                result = "string";
        }
        return result;
    }

    public static String getHiveColumnTypeDesc(Column column){
        if(column.isIncrement()){
            return "bigint";
        }else{
            return "string";
        }
    }

    public static String getHiveColumnTypeDesc(int type){
        if(type == 2){
            return "int";
        }else if(type == 5 || type == 7){
            return "bigint";
        }else if(type== 3){
            return "float";
        }else if(type== 4){
            return "double";
        }else if(type == 7){
            return "timestamp";
        }else{
            return "string";
        }
    }
}
